package com.phoenix.sgs.faq;

import com.phoenix.sgs.faq.adapter.SkillAdapter;
import com.phoenix.sgs.faq.general.Constants.Gender;
import com.phoenix.sgs.faq.general.General;
import com.phoenix.sgs.faq.general.Skill;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;
import android.widget.ListView;

public class GeneralDetailActivity extends Activity implements OnItemClickListener {
	SkillAdapter skillAdapter;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.generaldetail);
        
        Intent intent = this.getIntent();
    	int generalId = intent.getIntExtra("SelectedId", 0);
    	
    	General general = new General(this, generalId);
    	
    	TextView tvGeneralFullName = (TextView) findViewById(R.id.tvGeneralFullName);
    	TextView tvBlood = (TextView) findViewById(R.id.tvBlood);
    	TextView tvGender = (TextView) findViewById(R.id.tvGender);
    	
    	tvGeneralFullName.setText(general.getName() + " - " + general.getAlias());
    	tvBlood.setText(String.valueOf(general.getBlood()));
    	tvGender.setText(general.getGender() == Gender.male ? "男" : "女");
    	
    	ListView lvSkills = (ListView) findViewById(R.id.listViewSkills);
    	skillAdapter = new SkillAdapter(this, general.getSkills());
    	lvSkills.setAdapter(skillAdapter);
    	lvSkills.setOnItemClickListener(this);
	}
	
	@Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
		Skill skill = (Skill) skillAdapter.getItem(position);
		
		Intent intent = new Intent(this, GeneralFAQActivity.class);
		intent.putExtra("SelectedId", skill.getId());
    	startActivity(intent);
    }
}
